﻿using System;
using System.Web;

namespace NOSDC.Utility
{
    public class Helper
    {
        public static string GetIPAddress()
        {
            return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }

        public static string CreateSEOFriendlyURL(string text)
        {
            text = text.Replace(" ", "-");
            return text;
        }

        public static double ConvertBytesToMegabytes(long bytes)
        {
            return (bytes / 1024f) / 1024f;
        }

        public static string GetIconType(string extension)
        {
            string icon = String.Empty;

            switch(extension.ToLower())
            {
                case "txt":
                    icon = "doc rtf48";
                    break;
                case "rtf":
                    icon = "doc rtf48";
                    break;
                case "doc":
                    icon = "doc rtf48";
                    break;
                case "docx":
                    icon = "doc rtf48";
                    break;
                case "xls":
                    icon = "xls";
                    break;
                case "xlsx":
                    icon = "xls";
                    break;
                case "csv":
                    icon = "xls";
                    break;
                case "mov":
                    icon = "mov48";
                    break;
                case "avi":
                    icon = "avi";
                    break;
                case "mpg":
                    icon = "avi";
                    break;
                case "mpeg":
                    icon = "avi";
                    break;
                case "divx":
                    icon = "avi";
                    break;
                case "mp3":
                    icon = "avi";
                    break;
                case "pdf":
                    icon = "pdf2";
                    break;
                case "ppt":
                    icon = "ppt";
                    break;
                case "pptx":
                    icon = "ppt";
                    break;
                case "fla":
                    icon = "fla48";
                    break;
                case "sln":
                    icon = "visualstudio";
                    break;
                case "cs":
                    icon = "visualstudio";
                    break;
                case "vb":
                    icon = "visualstudio";
                    break;
                case "dll":
                    icon = "Dll";
                    break;
                case "so":
                    icon = "Dll";
                    break;
                case "lib":
                    icon = "Dll";
                    break;
                case "exe":
                    icon = "Exe";
                    break;
                case "zip":
                    icon = "zip rar";
                    break;
                case "rar":
                    icon = "zip rar";
                    break;
                case "tar":
                    icon = "zip rar";
                    break;
                case "targz":
                    icon = "zip rar";
                    break;
                default:
                    icon = "None";
                    break;
            }

            return String.Format(@"Icons/{0}.png", icon);
        }
    }
}